package com.ruoyi.teacher.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.teacher.domain.Teacher;
import com.ruoyi.teacher.domain.Type;
import com.ruoyi.teacher.mapper.TeacherDto;
import com.ruoyi.teacher.mapper.TypeDto;
import com.ruoyi.teacher.service.TeacherService;
import com.ruoyi.teacher.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.criteria.*;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherDto teacherDto;

    @Autowired
    private TypeService typeService;


    @Override
    public List<Teacher> getList(String name) {
        return teacherDto.findAll();
    }

    @Override
    public AjaxResult getSave(Teacher teacher) {
        Type byId = typeService.getById(Long.parseLong(teacher.getType()));
        String name = byId.getName();
        teacher.setType(name);
        Teacher save = teacherDto.save(teacher);
        return AjaxResult.success("成功", save);
    }

    @Transactional
    @Override
    public void getDelete(Long id) {
        teacherDto.deleteById(id);
    }
}
